//
//  CellForFirstMV.m
//  Movie
//
//  Created by dllo on 16/3/26.
//  Copyright © 2016年 HY. All rights reserved.
//

#import "CellForFirstMV.h"
#import "MovieModel.h"
#import <UIImageView+WebCache.h>

@implementation CellForFirstMV

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        [self createView];
    }
    return self;
}


- (void)createView{

    self.contentView.backgroundColor = [UIColor colorWithRed:40 / 255.f green:40 / 255.f blue:40 / 255.f alpha:1];
    
    self.img = [[UIImageView alloc] init];
    [self.contentView addSubview:self.img];
    
    self.imgForPlay = [[UIImageView alloc] init];
    [self.contentView addSubview:self.imgForPlay];
    
    self.labelForTime = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelForTime];

}

- (void)layoutSubviews{

    [super layoutSubviews];
    
    self.img.frame = CGRectMake(10, 15, self.contentView.frame.size.width - 20, self.contentView.frame.size.height - 30);
    self.img.layer.cornerRadius = 3;
    self.img.layer.masksToBounds = YES;
    
    self.labelForTime.frame = CGRectMake(self.img.frame.size.width - 80,self.img.frame.size.height - 20, 70, 20);
    self.labelForTime.textAlignment = NSTextAlignmentRight;
    self.labelForTime.textColor = [UIColor whiteColor];
    self.labelForTime.font = [UIFont boldSystemFontOfSize:17];
    self.labelForTime.shadowColor = [UIColor blackColor];
    self.labelForTime.shadowOffset = CGSizeMake(0.3, 0.3);
    
    self.imgForPlay.frame = CGRectMake(40, 40, 70, 70);
    self.imgForPlay.center = self.img.center;

    self.imgForPlay.image = [UIImage imageNamed:@"video-play"];
}

- (void)passModel:(MovieModel *)model{

    [self.img sd_setImageWithURL:[NSURL URLWithString:model.coverForDetail] placeholderImage:[UIImage imageNamed:@"zwt"]];
    
    NSInteger time = model.duration;
    
    NSString *timeString = [NSString stringWithFormat:@"%02ld'%02ld''",time/60,time% 60];    //音乐的总时间
    self.labelForTime.text = timeString;
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
